﻿using HCQ2_Common;
using HCQ2_Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using HCQ2_Model.ViewModel;
using HCQ2_Model.DocModel.APIParam;

namespace HCQ2UI_Logic.DocumentController
{
    /// <summary>
    ///  资源管理通用控制器
    /// </summary>
    public class SourceManagerController: BaseLogic
    {
        //**************************1.0 VR设备*****************************
        #region 1.0 默认首次进入VR设备 + ActionResult VRdeviceList()
        /// <summary>
        ///  默认首次进入VR设备
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRdeviceList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        //**************************1.1 VR云端作品*****************************
        #region 1.0 默认首次进入VR云端作品 + ActionResult DocList()
        /// <summary>
        ///  默认首次进入VR云端作品
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        //**************************1.2 VR云端素材*****************************
        #region 1.2 默认首次进入VR云端素材 + ActionResult VRMaterList()
        /// <summary>
        ///  默认首次进入VR云端素材
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRMaterList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        //**************************1.3 VR度度圈*****************************
        #region 1.3 默认首次进入VR度度圈 + ActionResult DocList()
        /// <summary>
        ///  默认首次进入VR度度圈
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRDDCircleList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        //**************************1.4 VR楼宇管理*****************************
        #region 1.4.1 默认首次进入VR楼宇管理 + ActionResult DocList()
        /// <summary>
        ///  默认首次进入VR楼宇管理
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRBuildingList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        #region 1.4.2 默认首次进入楼宇日志 + ActionResult VRBuildLogList()
        /// <summary>
        ///  默认首次进入楼宇日志
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRBuildLogList()
        {
            return View();
        }
        #endregion

        //**************************1.5 奇点元宇宙【应用管理】*****************************
        #region 1.5 默认首次进入奇点元宇宙【应用管理】 + ActionResult VRQDProgramList()
        /// <summary>
        ///  默认首次进入奇点元宇宙【应用管理】
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRQDProgramList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        #region 1.5.2 默认首次进入奇点元宇宙【房间管理】 + ActionResult VRQDRoomList()
        /// <summary>
        ///  默认首次进入奇点元宇宙【房间管理】
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRQDRoomList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        //**************************1.6 忆度元宇宙素材*****************************
        #region 1.6.1 默认首次进入忆度元宇宙素材 + ActionResult VRMaterList()
        /// <summary>
        ///  默认首次进入忆度元宇宙素材
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRQDMaterialList()
        {
            SetUserID();
            ViewBag.isApprive = operateContext.bllSession.T_DocumentInfo.IsApproveLimit(HCQ2UI_Helper.OperateContext.Current.Usr.user_id);
            return View();
        }
        #endregion

        #region 1.6.2 待审核素材 + ActionResult VRQDApproveList()
        /// <summary>
        /// 待审核素材
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult VRQDApproveList()
        {
            SetUserID();
            ViewBag.hasUnit = operateContext.bllSession.T_User.FindSingle(s => s.user_id == operateContext.Usr.user_id)?.unit_code; //单位
            return View();
        }
        #endregion

        //**************************2.0 待审核资源*****************************
        #region 2.0 默认首次进入待审核资源界面 + ActionResult ApproveList()
        /// <summary>
        ///  2.0 默认首次进入待审核资源界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult ApproveList()
        {
            SetUserID();
            ViewBag.hasUnit = operateContext.bllSession.T_User.FindSingle(s => s.user_id == operateContext.Usr.user_id)?.unit_code; //单位
            return View();
        }
        #endregion

        //**************************3.0 我的资源*****************************
        #region 3.0 默认首次进入我的资源界面 + ActionResult MyFileList()
        /// <summary>
        ///  3.0 默认首次进入我的资源界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult MyFileList()
        {
            SetUserID();
            return View();
        }
        #endregion

        //**************************4.0 我的分享*****************************
        #region 4.0 默认首次进入我的资源界面 + ActionResult MyShareList()
        /// <summary>
        ///  4.0 默认首次进入我的我的分享界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult MyShareList()
        {
            SetUserID();
            return View();
        }
        #endregion

        //**************************5.0 收到的分享*****************************
        #region 5.0 默认首次进入收到的分享界面 + ActionResult GetShareList()
        /// <summary>
        ///  5.0 默认首次进入收到的分享界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult GetShareList()
        {
            SetUserID();
            return View();
        }
        #endregion

        //**************************6.0 已下架资源*****************************
        #region 6.0 默认首次进入已下架资源界面 + ActionResult RecycleList()
        /// <summary>
        ///  6.0 默认首次进入已下架资源界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult RecycleList()
        {
            SetUserID();
            return View();
        }
        #endregion

        //**************************7.0 获取缩略图*****************************
        #region 7.0 获取缩略图 + ActionResult GetPicUrlByID(int id)
        /// <summary>
        ///  获取缩略图
        /// </summary>
        /// <param name="id">文档ID</param>
        /// <returns></returns>
        public ActionResult GetPicUrlByID(int id)
        {
            if (id <= 0)
                return operateContext.RedirectAjax(1, "文档ID不能为空~", "", "");
            string picType = RequestHelper.GetStrByName("picType");
            string pageType = RequestHelper.GetStrByName("pageType");//页面类型
            if (string.IsNullOrEmpty(picType))
            {
                //缩略图
                //1.0 统计浏览次数
                T_DocumentInfo info = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id == id).FirstOrDefault();
                info.browse_num = info.browse_num + 1;
                operateContext.bllSession.T_DocumentInfo.Modify(info, s => s.file_id == id, "browse_num");
                List<T_DocBagFileRecord> resord = operateContext.bllSession.T_DocBagFileRecord.Select(s => s.file_id.Equals(id)).OrderBy(s => s.bag_id).ToList();
                if (resord == null || resord.Count <= 0)
                    return operateContext.RedirectAjax(1, "当前文档未上传缩略图~", "", "");
                return operateContext.RedirectAjax(0, "成功获取缩略图~", resord, "");
            }
            else
            {
                //目录树头像
                List<Dictionary<string, object>> resord = new List<Dictionary<string, object>>();
                if (!string.IsNullOrEmpty(pageType) && pageType.Equals("VRBuilding"))
                {
                    //楼宇管理【目录缩略图表获取】
                    List<T_DocBagFolderRecord> list = operateContext.bllSession.T_DocBagFolderRecord.Select(s => s.folder_id.Equals(id)).OrderBy(s => s.bag_id).ToList();
                    if (list == null || list.Count <= 0)
                        return operateContext.RedirectAjax(1, "当前目录未上传缩略图~", "", "header");
                    list?.ForEach(s =>
                    {
                        Dictionary<string, object> temp = new Dictionary<string, object>();
                        temp.Add("folder_id", s.bag_id);
                        temp.Add("folder_name", s.folder_name);
                        temp.Add("folder_type", s.folder_type);
                        temp.Add("folder_url", s.file_url);
                        temp.Add("page_type", pageType);
                        resord.Add(temp);
                    });
                    return operateContext.RedirectAjax(0, "成功获取缩略图~", resord, "header");
                }
                else
                {
                    //其他业务目录缩略图
                    T_DocumentFolder folder = operateContext.bllSession.T_DocumentFolder.Select(s => s.folder_id == id).FirstOrDefault();
                    Dictionary<string, object> temp = new Dictionary<string, object>();
                    temp.Add("folder_id", folder.folder_id);
                    temp.Add("folder_name", folder.folder_name);
                    temp.Add("folder_type", 0);
                    temp.Add("folder_url", folder.folder_url);
                    temp.Add("page_type", pageType);
                    resord.Add(temp);
                    return operateContext.RedirectAjax(0, "当前文档未上传缩略图~", resord, "header");
                }
            }
        }
        #endregion

        #region 7.1 缩略图上传页面 + ActionResult DocUpPicFile()
        /// <summary>
        ///  缩略图上传页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult DocUpPicFile()
        {
            return View();
        }
        #endregion

        #region 7.2 批量上传缩略图 + ActionResult UpPicLoadFile()
        /// <summary>
        ///  批量上传缩略图
        /// </summary>
        /// <param name="id">文档ID</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult UpPicLoadFile(int id)
        {
            string pic_type = RequestHelper.GetStrByName("pic_type");//类别 空：缩略图，header：目录图标
            int fileType = RequestHelper.GetIntByName("fileType");//图片类别 0：横版缩略图（4:3）；1：竖版缩略图（3:4）
            string pageType = RequestHelper.GetStrByName("pageType");//页面类型
            var files = Request.Files;
            if (id <= 0 || files == null || files.Count <= 0)
                return null;
            List<string> uuid = new List<string>();
            List<T_DocBagFileRecord> listRecord = new List<T_DocBagFileRecord>();

            #region 目录图标
            if (pic_type.Equals("header"))
            {
                List<Dictionary<string, object>> folderRecoed = new List<Dictionary<string, object>>();
                #region 1.0 处理上传文件夹
                string pathServer = "/uploadFile/FolderFile/" + operateContext.Usr.user_guid + "/" + DateTime.Now.ToString("yyyyMMdd") + "/picture/";
                string uploadPath = request.MapPath(request.ApplicationPath + pathServer);
                if (!Directory.Exists(uploadPath))
                    Directory.CreateDirectory(uploadPath);
                #endregion

                #region 2.0 处理文档
                try
                {
                    #region 楼宇
                    if (!string.IsNullOrEmpty(pageType) && pageType.Equals("VRBuilding"))
                    {
                        for (int i = 0; i < files.Count; i++)
                        {
                            HttpPostedFileBase file = files[i];
                            if (null == file)
                                continue;
                            string file_name = Helper.GetGuid;//重置文件名
                            string file_url = "~" + pathServer + file_name + file.FileName.Substring(file.FileName.LastIndexOf("."));
                            uuid.Add(file_url);
                            //1.上传文档
                            file.SaveAs(Server.MapPath(file_url));//上传文件
                            string fileName = file.FileName.Split('.')[0];//文件名
                            //2.保存文档信息
                            var bag = new T_DocBagFolderRecord
                            {
                                folder_id = id,
                                folder_name = fileName,
                                folder_type = fileType,
                                file_url = file_url,
                                create_date = DateTime.Now,
                                create_name = operateContext.Usr.user_name,
                                create_id = operateContext.Usr.user_id
                            };
                            operateContext.bllSession.T_DocBagFolderRecord.Add(bag);
                            Dictionary<string, object> temp = new Dictionary<string, object>();
                            temp.Add("folder_id", bag.bag_id);
                            temp.Add("folder_url", file_url);
                            temp.Add("folder_name", fileName);
                            temp.Add("folder_type", fileType);
                            temp.Add("page_type", pageType);
                            folderRecoed.Add(temp);
                        }
                        return operateContext.RedirectAjax(0, "图标上传成功~", folderRecoed, "header");
                    }
                    #endregion

                    #region 其他
                    else
                    {
                        //删除之前的图标
                        T_DocumentFolder fodlers = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == id);
                        if (!string.IsNullOrEmpty(fodlers.folder_url))
                        {
                            if (System.IO.File.Exists(Server.MapPath(fodlers.folder_url)))
                                System.IO.File.Delete(Server.MapPath(fodlers.folder_url));
                        }
                        for (int i = 0; i < files.Count; i++)
                        {
                            HttpPostedFileBase file = files[i];
                            if (null == file)
                                continue;
                            string file_name = Helper.GetGuid;//重置文件名
                            string file_url = "~" + pathServer + file_name + file.FileName.Substring(file.FileName.LastIndexOf("."));
                            uuid.Add(file_url);
                            //1.上传文档
                            file.SaveAs(Server.MapPath(file_url));//上传文件
                            //2.保存文档信息
                            fodlers.folder_url = file_url;
                            operateContext.bllSession.T_DocumentFolder.Modify(fodlers, s => s.folder_id == id, "folder_url");
                        }
                        Dictionary<string, object> temp = new Dictionary<string, object>();
                        temp.Add("folder_id", id);
                        temp.Add("folder_url", fodlers.folder_url);
                        temp.Add("folder_name", fodlers.folder_name);
                        temp.Add("folder_type", 0);
                        temp.Add("page_type", pageType);
                        folderRecoed.Add(temp);
                        return operateContext.RedirectAjax(0, "图标上传成功~", folderRecoed, "header");
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    foreach (string url in uuid)
                        System.IO.File.Delete(Server.MapPath(url));
                    return operateContext.RedirectAjax(1, ex.Message, "", "");
                }
                #endregion
            }
            #endregion

            #region 缩略图
            else
            {
                #region 1.0 处理上传文件夹
                string pathServer = "/uploadFile/VRFile/" + operateContext.Usr.user_guid + "/" + DateTime.Now.ToString("yyyyMMdd") + "/picture/";
                string uploadPath = request.MapPath(request.ApplicationPath + pathServer);
                if (!Directory.Exists(uploadPath))
                    Directory.CreateDirectory(uploadPath);
                #endregion

                #region 2.0 处理文档
                try
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFileBase file = files[i];
                        if (null == file)
                            continue;
                        string file_name = Helper.GetGuid;//重置文件名
                        string file_url = "~" + pathServer + file_name + file.FileName.Substring(file.FileName.LastIndexOf("."));
                        uuid.Add(file_url);
                        //1.上传文档
                        file.SaveAs(Server.MapPath(file_url));//上传文件
                        //2.保存文档信息
                        string fileName = file.FileName.Split('.')[0];//文件名
                        T_DocBagFileRecord record = new T_DocBagFileRecord
                        { 
                            file_id = id,
                            create_date = DateTime.Now,
                            create_name = operateContext.Usr.user_name,
                            create_id = operateContext.Usr.user_id,
                            file_name = fileName,
                            file_url = file_url,
                            file_type = fileType
                        };
                        operateContext.bllSession.T_DocBagFileRecord.Add(record);
                        listRecord.Add(record);
                    }
                    return operateContext.RedirectAjax(0, "文档上传成功~", listRecord, "");
                }
                catch (Exception ex)
                {
                    foreach (string url in uuid)
                        System.IO.File.Delete(Server.MapPath(url));
                    return operateContext.RedirectAjax(1, ex.Message, "", "");
                }
                #endregion
            }
            #endregion
        }
        #endregion

        #region 7.3 删除缩略图 + ActionResult DelPicUrlByID(int id)
        /// <summary>
        ///  删除缩略图
        /// </summary>
        /// <param name="id">文档ID</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelPicUrlByID(int id)
        {
            if (id <= 0)
                return operateContext.RedirectAjax(1, "指定缩略图不能为空~", "", "");
            string picType = RequestHelper.GetStrByName("picType"),
            pageType = RequestHelper.GetStrByName("pageType");
            if (!string.IsNullOrEmpty(picType) && picType== "header")
            {
                if(!string.IsNullOrEmpty(pageType) && pageType.Equals("VRBuilding"))
                {
                    //楼宇目录
                    var list = operateContext.bllSession.T_DocBagFolderRecord.Select(s => s.bag_id == id);
                    list?.ForEach(s =>
                    {
                        if(!string.IsNullOrEmpty(s.file_url) && System.IO.File.Exists(Server.MapPath(s.file_url)))
                            System.IO.File.Delete(Server.MapPath(s.file_url));
                    });
                    operateContext.bllSession.T_DocBagFolderRecord.Delete(s => s.bag_id == id);
                }
                else
                {
                    //其他目录
                    T_DocumentFolder fodler = operateContext.bllSession.T_DocumentFolder.Select(s => s.folder_id == id).FirstOrDefault();
                    //2.0 删除文件
                    if (System.IO.File.Exists(Server.MapPath(fodler.folder_url)))
                        System.IO.File.Delete(Server.MapPath(fodler.folder_url));
                    operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { folder_url = "" }, s => s.folder_id == id, "folder_url");
                }
                return operateContext.RedirectAjax(0, "删除图标成功~", "", "");
            }
            else
            {
                //缩略图
                T_DocBagFileRecord rescord = operateContext.bllSession.T_DocBagFileRecord.Select(s => s.bag_id.Equals(id)).FirstOrDefault();
                if (rescord == null)
                    return operateContext.RedirectAjax(1, "指定的缩略图不存在~", "", "");
                //1.0 删除数据库连接
                int mark = operateContext.bllSession.T_DocBagFileRecord.Delete(s => s.bag_id.Equals(id));
                //2.0 删除文件
                if (System.IO.File.Exists(Server.MapPath(rescord.file_url)))
                    System.IO.File.Delete(Server.MapPath(rescord.file_url));
                if (mark <= 0)
                    return operateContext.RedirectAjax(1, "删除缩略图失败~", "", "");
                return operateContext.RedirectAjax(0, "删除缩略图成功~", "", "");
            }
        }
        #endregion

        //**************************8.0 共享资源*****************************
        #region 8.0 共享资源 + ActionResult PublicShareList()
        /// <summary>
        ///  共享资源
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult PublicShareList()
        {
            SetUserID();
            return View();
        }
        #endregion

        //设置返回参数
        private void SetUserID ()
        {
            List<T_Permissions> list = HCQ2UI_Helper.Session.SysPermissSession.PermissList.FindAll(s => s.per_type.Equals("docSystem"));
            ViewBag.isdocManager = true; //(null == list || list.Count <= 0) ? false : true;
            ViewBag.userID = HCQ2UI_Helper.OperateContext.Current.Usr.user_id;
        }

        //**************************9.0 购买商品*****************************
        #region 9.1 购买商品 + ActionResult PayShoppingCart()
        /// <summary>
        ///  加入购物车
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult PayShoppingCart()
        {
            int file_id=RequestHelper.GetIntByName("file_id"),
                myCart = RequestHelper.GetIntByName("myCart");
            string userid = RequestHelper.GetStrByName("userid");
            decimal file_price = Convert.ToDecimal(RequestHelper.GetStrByName("file_price"));
            T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id.Equals(file_id)).FirstOrDefault();
            if(file==null)
                return operateContext.RedirectAjax(1, "商品异常~", "", "");
            if (myCart <= 0)
            {
                #region 帮别人购买
                if (string.IsNullOrEmpty(userid))
                    return operateContext.RedirectAjax(1, "购买用户设置异常~", "", "");
                string[] ids = userid.Split(',');
                List<int> shopping = new List<int>();//已购买用户
                List<int> cart = new List<int>();//已添加购物车用户
                foreach(var item in ids)
                {
                    int user_id = Helper.ToInt(item);
                    int mark = operateContext.bllSession.T_VROrder.GetShoppingFile(file_id, user_id);
                    if(mark>0)
                        continue;//已购买
                    mark = operateContext.bllSession.T_VRShoppingCart.GetCartFile(file_id, user_id);
                    if (mark > 0)
                        continue;//已添加至购物车
                    //添加购物车
                    operateContext.bllSession.T_VRShoppingCart.Add(new T_VRShoppingCart { file_id = file_id, user_id = user_id, price = file_price });
                }
                #endregion
            }
            else
            {
                #region 自己购买
                int mark = operateContext.bllSession.T_VROrder.GetShoppingFile(file_id, operateContext.Usr.user_id);
                if (mark > 0)
                    return operateContext.RedirectAjax(1, "此商品已经购买过~", "", "");//已购买
                mark = operateContext.bllSession.T_VRShoppingCart.GetCartFile(file_id, operateContext.Usr.user_id);
                if (mark > 0)
                    return operateContext.RedirectAjax(1, "此商品已经添加至购物车，请到购物车查看~", "", "");//已添加至购物车
                //添加购物车
                operateContext.bllSession.T_VRShoppingCart.Add(new T_VRShoppingCart { file_id = file_id, user_id = operateContext.Usr.user_id, price = file_price });
                #endregion
            }
            return operateContext.RedirectAjax(0, "此商品已经添加至购物车，请到购物车查看~", "", "");
        }
        #endregion

        #region 9.2 添加收藏夹【收藏作品】 + ActionResult PayFolderByUser(int id)
        /// <summary>
        ///  添加收藏夹
        /// </summary>
        /// <param name="id">素材/作品ID</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult PayFolderByUser(int id)
        {
            //1.0  判断当前商品是否已添加至收藏夹
            int user_id = operateContext.Usr.user_id;
            int mark = operateContext.bllSession.T_VRFavoriteGoods.SelectCount(s => s.file_id == id && s.user_id == user_id);
            if(mark>0)
                return operateContext.RedirectAjax(1, "此商品已经添加至收藏夹，请到我的收藏中查看！", "", "");
            //1.1 添加收藏夹
            mark = operateContext.bllSession.T_VRFavoriteGoods.Add(new T_VRFavoriteGoods { file_id = id, user_id = user_id,create_date=DateTime.Now });
            if(mark>0)
                return operateContext.RedirectAjax(0, "此商品已经添加至收藏夹，请到我的收藏中查看！", "", "");
            return operateContext.RedirectAjax(1, "此商品添加至收藏夹失败！", "", "");
        }
        #endregion

        #region 9.3 设置/取消热门推荐 + ActionResult ModifyIsHot(int id)
        /// <summary>
        ///  设置/取消热门推荐
        /// </summary>
        /// <param name="id">素材/作品ID</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult ModifyIsHot(int id)
        {
            int isHot = RequestHelper.GetIntByName("isHot");
            int mark = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == id && !s.if_remove && s.file_status == 5);
            if(mark<=0)
                return operateContext.RedirectAjax(1, "商品id有误！", "", "");
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { isHot = isHot > 0 ? true : false }, s => s.file_id == id, "isHot");
            return operateContext.RedirectAjax(0, "商品是否热门推荐设置成功！", "", "");
        }
        #endregion

        //**************************10.0 编辑、详细作品相关操作************
        #region 10.0 进入作品编辑页面 + ActionResult EntryFile()
        /// <summary>
        ///  进入作品编辑页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult EntryFile()
        {
            int id=RequestHelper.GetIntByName("file_id"),file_status;
            string mater_type = RequestHelper.GetStrByName("pageType");
            ViewBag.priceTitle = "";
            ViewBag.priceMoney = "";
            if (id <= 0)
            {
                //新增
                ViewBag.goodPrice = new List<T_VRGoodDisiPrice>();
                ViewBag.goodStatus = 0; 
            }
            else
            {
                //编辑
                var price= GetGoodPrice(id, out file_status);
                ViewBag.goodPrice = price;
                ViewBag.goodStatus = file_status;
                if (mater_type.Equals("QDMaterial") && price!=null && price.Count>0)
                {
                    ViewBag.priceTitle = price[0].op_month;
                    ViewBag.priceMoney = price[0].ori_price;
                }
            }
            ViewBag.materType = mater_type;
            //素材
            if (mater_type.Equals("VRManager") || mater_type.Equals("QDMaterial"))
                return View("EntryFileMater");
            //度度圈新增
            if (mater_type.Equals("DDCircle") && id<=0)
                return View("EntryFileDDCircle");
            //作品、组件
            return View();
        }
        #endregion

        #region 10.1 进入奇点元宇宙编辑页面 + ActionResult EntryFileMeta()
        /// <summary>
        ///  进入奇点元宇宙编辑页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult EntryFileMeta()
        {
            int id = RequestHelper.GetIntByName("file_id"), file_status;
            if (id <= 0)
            {
                //新增
                ViewBag.goodPrice = new List<T_VRGoodDisiPrice>();
                ViewBag.goodStatus = 0;
            }
            else
            {
                //编辑
                ViewBag.goodPrice = GetGoodPrice(id, out file_status);
                ViewBag.goodStatus = file_status;
            }
            return View();
        }
        #endregion

        #region 10.1 获取作品数据 + ActionResult GetEntryData(int id)
        /// <summary>
        ///  获取作品数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetEntryData(int id)
        {
            T_DocumentInfo info = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_id == id).FirstOrDefault();
            if(info==null)
                return operateContext.RedirectAjax(1, "数据为空~", "", "");
            T_DocumentFolder folder = operateContext.bllSession.T_DocumentFolder.GetFolderByFileId(info.file_id);
            Dictionary<string, object> map = new Dictionary<string, object>();
            map.Add("info", info);
            map.Add("folder", folder);
            return operateContext.RedirectAjax(0, "数据获取成功~", map, "");
        }
        #endregion

        #region 10.1.1 编辑保存作品数据 + ActionResult SaveEntryData(T_DocumentInfo file)
        /// <summary>
        ///  保存作品数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveEntryData(DocumentModel file)
        {
            try
            {
                int fileStatus = RequestHelper.GetIntByName("fileStatus"),
                    all_status = RequestHelper.GetIntByName("all_status"),
               folder_id = RequestHelper.GetIntByName("folder_id"),
               isSoldOut = RequestHelper.GetIntByName("isSoldOut"),//是否已售馨
               isHot = RequestHelper.GetIntByName("isHot"),//是否热门推荐
               status = RequestHelper.GetIntByName("status");//0：私有；1：公开；2：重新审核；
                string folder_path = RequestHelper.GetStrByName("folder_path"),
                    sourceType = RequestHelper.GetStrByName("sourceType"),//类别 
                    saveType = RequestHelper.GetStrByName("saveType"),//保存类别 approve 审核，other 编辑
                    entryType = RequestHelper.GetStrByName("entryType");//状态，approve：审核
                string isHeader = RequestHelper.GetStrByName("isHeader");//是否为头记
                file.isHot = isHot > 0 ? true : false;
                file.isSoldOut = isSoldOut > 0 ? true : false;
                //判断课件代码
                if (string.IsNullOrEmpty(file.file_code))
                    return operateContext.RedirectAjax(1, "代码必填字段不允许为空~", "", "");
                int fileTemp = 0;
                if (fileStatus == 5)
                    fileTemp = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_code.Equals(file.file_code, StringComparison.CurrentCultureIgnoreCase) && s.file_id != file.file_id && s.file_status == 5);
                if (fileTemp > 0)
                    return operateContext.RedirectAjax(1, "当前课件代码已成功上架、请重新编辑代码 或者 下架同代码的课件！注意：代码不区分大小写~", "", "");
                if (!entryType.Equals("approve"))
                {
                    if (status == 2 || (status == 1 && file.file_status == 0))
                        file.file_status = 1;//重新审核
                    if (status == 0)
                        file.file_status = 0;//设置为私有
                    else
                        file.file_status = all_status;
                }
                if (string.IsNullOrEmpty(file.file_classify))
                    file.file_classify = "";
                if (!string.IsNullOrEmpty(file.doc_number))
                    file.doc_number = file.doc_number.Replace('，', ',').Trim(',');
                file.update_name = operateContext.Usr.user_name;
                file.update_time = DateTime.Now;
                string[] temp = { "file_classify", "file_name", "browse_num", "vr_star", "file_status", "talk_num", "down_number", "folder_limit", "alias_name", "file_note", "pro_type", "update_name", "update_time", "allow_edit", "org_unit", "unit_code", "pro_form", "file_code", "is_recommend", "supplyType", "out_link","gps_x","gps_y", "doc_number", "pay_num", "isHot", "vUrl", "isSoldOut" };
                List<string> modifyStr = new List<string>(temp);
                if (entryType.Equals("approve"))
                {
                    file.approve_time = DateTime.Now;
                    int isRecommend = RequestHelper.GetIntByName("is_recommend");
                    if (isRecommend > 0)
                        file.is_recommend = true;
                    else
                        file.is_recommend = false;
                    file.approve_name = operateContext.Usr.user_name;
                    modifyStr.Add("approve_time");
                    modifyStr.Add("approve_name");
                    modifyStr.Add("approve_note");
                }
                if (saveType.Equals("other"))
                    modifyStr.Add("file_order");//序号
                #region 判断是否更新头记比赛课件字段
                if (!string.IsNullOrEmpty(isHeader) && isHeader.Equals("ok"))
                {
                    modifyStr.Add("is_game");
                    modifyStr.Add("game_start");
                    modifyStr.Add("game_end");
                    string game_start = RequestHelper.GetStrByName("game_start"),
                        game_end = RequestHelper.GetStrByName("game_end");
                    if (!string.IsNullOrEmpty(game_start))
                        file.game_start = Convert.ToDateTime(game_start);
                    if (!string.IsNullOrEmpty(game_end))
                        file.game_end = Convert.ToDateTime(game_end);
                }
                #endregion
                //判断是否素材
                if (sourceType.Equals("mater"))
                    modifyStr.Add("mater_type");//素材编辑时更新，格式
                if (file.listPrice != null && file.listPrice.Count > 0)
                {
                    file.file_money = file.listPrice[0].file_price;
                    modifyStr.Add("file_money");//最小金额
                }
                //更新之前判断file_code是否被正确修改
                int fileCount = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_code.Equals(file.file_code) && s.file_id != file.file_id && s.file_status == 5);
                if (fileCount > 0)
                    return operateContext.RedirectAjax(1, $"修改后的代码【{file.file_code}】已在上架商品中存在，请重新设置！", "", "");
                int mark = operateContext.bllSession.T_DocumentInfo.Modify(file, s => s.file_id == file.file_id, modifyStr.ToArray());
                if (mark > 0)
                {
                    T_DocumentFolderRelation rel = operateContext.bllSession.T_DocumentFolderRelation.Select(s => s.file_id == file.file_id).FirstOrDefault();
                    if (rel != null)
                        operateContext.bllSession.T_DocumentFolderRelation.Modify(new T_DocumentFolderRelation { folder_id = folder_id, folder_path = folder_path }, s => s.fr_id == rel.fr_id, "folder_id", "folder_path");
                    else
                        operateContext.bllSession.T_DocumentFolderRelation.Add(new T_DocumentFolderRelation { file_id = file.file_id, create_id = file.create_id, folder_id = folder_id, folder_path = folder_path });
                    //更新金额
                    operateContext.bllSession.T_VRGoodDisiPrice.Delete(s => s.file_id == file.file_id);
                    if (file.listPrice != null && file.listPrice.Count > 0)
                    {
                        file.listPrice.ForEach(s =>
                        {
                            operateContext.bllSession.T_VRGoodDisiPrice.Add(new T_VRGoodDisiPrice
                            {
                                op_code = Helper.GetGuid,
                                file_id = file.file_id,
                                file_code = file.file_code,
                                op_month = s.op_month,
                                ori_price = s.file_price
                            });
                        });
                    }
                    //List<T_VRGoodDisiPrice> priceList = operateContext.bllSession.T_VRGoodDisiPrice.Select(s => s.file_id == file.file_id);
                    //if (file.listPrice != null && file.listPrice.Count > 0)
                    //{
                    //    file.listPrice.ForEach(s =>
                    //    {
                    //        var query = priceList.Where(o => o.op_month == s.op_month).FirstOrDefault();
                    //        if (query != null)
                    //            operateContext.bllSession.T_VRGoodDisiPrice.Modify(new T_VRGoodDisiPrice { ori_price = s.file_price }, o => o.op_code.Equals(query.op_code), "ori_price");
                    //        else
                    //        {
                    //            operateContext.bllSession.T_VRGoodDisiPrice.Add(new T_VRGoodDisiPrice
                    //            {
                    //                op_code = Helper.GetGuid,
                    //                file_id = file.file_id,
                    //                file_code = file.file_code,
                    //                op_month = s.op_month,
                    //                ori_price = s.file_price
                    //            });
                    //        }
                    //    });
                    //}
                    return operateContext.RedirectAjax(0, "数据更新成功~", "", "");
                }
                return operateContext.RedirectAjax(1, "数据更新失败~", "", "");
            }
            catch (Exception ex)
            {
                return operateContext.RedirectAjax(1, ex.Message, "", "");
            }          
        }
        #endregion

        #region 10.1.2 添加无附件素材数据 + ActionResult AddVRManagerEntryData(AddEntryData file)
        /// <summary>
        ///  10.1.2 添加无附件素材数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddVRManagerEntryData(AddEntryData file)
        {
            try
            {
                int folder_id = RequestHelper.GetIntByName("folder_id");
                string folder_path = RequestHelper.GetStrByName("folder_path");
                string page_type= RequestHelper.GetStrByName("page_type");
                //判断课件代码
                if (string.IsNullOrEmpty(file.info.file_code))
                    file.info.file_code = DateTime.Now.ToString("yyyyMMddHHmmss");
                if (string.IsNullOrEmpty(file.info.folder_num))
                    file.info.folder_num = "";
                if (string.IsNullOrEmpty(file.info.doc_type))
                    file.info.doc_type = "";
                if (string.IsNullOrEmpty(file.info.file_classify))
                    file.info.file_classify = "";
                if (!string.IsNullOrEmpty(file.info.doc_number))
                    file.info.doc_number = file.info.doc_number.Replace('，', ',').Trim(',');
                if(!string.IsNullOrEmpty(page_type))
                    file.info.page_type = page_type;
                else
                    file.info.page_type = "VRManager";
                //if (file.info.page_type.Equals("QDMaterial"))
                //    file.info.file_status = 1;
                //else
                file.info.file_status = 5;
                file.info.file_money = file.listPrice[0].file_price;
                file.info.create_id = operateContext.Usr.user_id;
                file.info.create_name = operateContext.Usr.user_name;
                file.info.create_time = DateTime.Now;
                file.info.update_name = operateContext.Usr.user_name;
                file.info.update_time = DateTime.Now;
                //添加之前判断file_code是否被正确修改
                var fileObj = operateContext.bllSession.T_DocumentInfo.FindSingle(s => s.file_code.Equals(file.info.file_code) && s.file_status == 5);
                if (fileObj!=null && file.info.file_id!=fileObj.file_id)
                    return operateContext.RedirectAjax(1, $"编辑的素材代码【{file.info.file_code}】已在上架商品中存在，请重新设置！", "", "");
                if(file.info.file_id<=0 && fileObj != null)
                    return operateContext.RedirectAjax(1, $"添加的素材代码【{file.info.file_code}】已在上架商品中存在，请重新设置！", "", "");
                int mark = operateContext.bllSession.T_DocumentInfo.Add(file.info);
                if (mark > 0)
                {
                    //素材-目录关联关系
                    operateContext.bllSession.T_DocumentFolderRelation.Add(new T_DocumentFolderRelation { file_id = file.info.file_id, create_id = file.info.create_id, folder_id = folder_id, folder_path = folder_path });
                    //保存金额
                    file.listPrice?.ForEach(o =>
                    {
                        operateContext.bllSession.T_VRGoodDisiPrice.Add(new T_VRGoodDisiPrice
                        {
                            op_code = Helper.GetGuid,
                            file_id = file.info.file_id,
                            file_code = file.info.file_code,
                            op_month = o.op_month,
                            ori_price = o.file_price
                        });
                    });
                    return operateContext.RedirectAjax(0, "素材数据保存成功~", file.info.file_id.ToString(), "");
                }
                return operateContext.RedirectAjax(1, "素材数据保存失败~", "", "");
            }
            catch (Exception ex)
            {
                return operateContext.RedirectAjax(1, ex.Message, "", "");
            }
        }
        #endregion

        #region 10.1.2 添加作品数据 + ActionResult AddEntryData(T_DocumentInfo file)
        /// <summary>
        ///  添加作品数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddEntryData(T_DocumentInfo file)
        {
            try
            {
                int folder_id = RequestHelper.GetIntByName("folder_id"),
                     isSoldOut = RequestHelper.GetIntByName("isSoldOut"),//是否已售馨
                    isHot = RequestHelper.GetIntByName("isHot");//是否热门推荐
                string folder_path = RequestHelper.GetStrByName("folder_path");
                decimal file_price = RequestHelper.GetDecimalByName("file_price");
                file.isHot = isHot > 0 ? true : false;
                file.isSoldOut = isSoldOut > 0 ? true : false;
                //判断课件代码
                if (string.IsNullOrEmpty(file.file_code))
                    return operateContext.RedirectAjax(1, "代码必填字段不允许为空~", "", "");
                //判断作品是否已经上传
                int fileTemp = 0;
                if (file.file_status == 5)
                    fileTemp = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_code.Equals(file.file_code, StringComparison.CurrentCultureIgnoreCase) && s.file_status == 5);
                if (fileTemp > 0)
                    return operateContext.RedirectAjax(1, "当前课件代码已成功上架、请重新编辑代码 或者 下架同代码的课件！注意：代码不区分大小写~", "", "");
                file.create_id = operateContext.Usr.user_id;
                file.create_name = operateContext.Usr.user_name;
                file.create_time = DateTime.Now;
                file.update_name= operateContext.Usr.user_name;
                file.update_time = DateTime.Now;
                if (string.IsNullOrEmpty(file.file_classify))
                    file.file_classify = "";
                if (string.IsNullOrEmpty(file.doc_type))
                    file.doc_type = "";
                int mark = operateContext.bllSession.T_DocumentInfo.Add(file);
                if (mark > 0)
                {
                    //保存对应关系
                     operateContext.bllSession.T_DocumentFolderRelation.Add(new T_DocumentFolderRelation { file_id = file.file_id, create_id = file.create_id, folder_id = folder_id, folder_path = folder_path });
                    //保存金额
                    if (file_price > 0)
                    {
                        operateContext.bllSession.T_VRGoodDisiPrice.Add(new T_VRGoodDisiPrice
                        {
                            op_code = Helper.GetGuid,
                            file_id = file.file_id,
                            file_code = file.file_code,
                            op_month = 1,
                            ori_price = file_price
                        });
                    }
                    return operateContext.RedirectAjax(0, "数据添加成功~", "", "");
                }
                return operateContext.RedirectAjax(1, "数据添加失败~", "", "");
            }
            catch (Exception ex)
            {
                return operateContext.RedirectAjax(1, ex.Message, "", "");
            }
        }
        #endregion

        #region 11.0 进入作品附件列表页面 + ActionResult EntryFileList()
        /// <summary>
        ///  进入作品附件列表页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult EntryFileList()
        {
            return View();
        }
        #endregion

        #region 11.1 获取作品附件列表 + ActionResult GetEntryFileListData()
        /// <summary>
        ///  获取作品附件列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetEntryFileListData()
        {
            int file_id = RequestHelper.GetIntByName("file_id");
            if(file_id<=0)
                return operateContext.RedirectAjax(1, "作品ID关键字段为空~", "", "");
            List<T_DocFileOptions> info = operateContext.bllSession.T_DocFileOptions.Select(s => s.file_id == file_id);
            info?.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s.option_url))
                    s.service_id = HCQ2UI_Helper.OperateContext.GetServiceUrl(s.service_id) + s.option_url;
            });
            TableModel tModel = new TableModel()
            {
                total = info.Count,
                rows = info
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 11.2 修改作品附件信息 + ActionResult SaveEntryFileData(int id)
        /// <summary>
        ///  修改作品附件信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveEntryFileData(T_DocFileOptions option)
        {
            int mark = operateContext.bllSession.T_DocFileOptions.Modify(option, s => s.option_id == option.option_id, "head_facility", "file_money", "option_plat");
            if (mark > 0)
                return operateContext.RedirectAjax(0, "数据更新成功~", "", "");
            return operateContext.RedirectAjax(1, "数据更新失败~", "", "");
        }
        #endregion

        #region 11.3 获取商品价格列表 + ActionResult GetPriceList(int id)
        /// <summary>
        ///  获取商品价格列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetPriceList(int id)
        {
            int fileStatus;
            List<T_VRGoodDisiPrice> list = GetGoodPrice(id,out fileStatus);
            return operateContext.RedirectAjax(0, "数据更新成功~", list, "");
        }
        #endregion

        #region 获取商品价格列表：商品id
        private List<T_VRGoodDisiPrice> GetGoodPrice(int fileId, out int file_status)
        {
            file_status = 0;
            List<T_VRGoodDisiPrice> list = new List<T_VRGoodDisiPrice>();
            T_DocumentInfo file = operateContext.bllSession.T_DocumentInfo.FindSingle(s => s.file_id == fileId);
            if (file == null || file.file_status == 0)
                return list;
            file_status = file.file_status;
            return operateContext.bllSession.T_VRGoodDisiPrice.Select(s => s.file_id == fileId, s => s.ori_price, true);
        }
        #endregion

        #region 获取商品价格列表：商品code
        private List<T_VRGoodDisiPrice> GetGoodPrice(string fileCode)
        {
            int? file_id = operateContext.bllSession.T_DocumentInfo.Select(s => s.file_code.Equals(fileCode) && s.file_status == 5).FirstOrDefault()?.file_id;
            if (file_id == null || file_id <= 0)
                throw new Exception("商品代码对应的已上架商品不存在！");
            return operateContext.bllSession.T_VRGoodDisiPrice.Select(s => s.file_id == file_id, s => s.op_month, true);
        }
        #endregion

        //**************************11.0 审批商品*****************************
        #region 10.0 进入作品编辑页面 + ActionResult EntryFileApprove()
        /// <summary>
        ///  进入作品编辑页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult EntryFileApprove()
        {
            string pageType = RequestHelper.GetStrByName("pageType"), strTitle = "产品形态";
            if (pageType.Equals("VRWorks"))
                strTitle = "作品格式";
            ViewBag.proTitle = strTitle;
            return View();
        }
        #endregion

        //**************************12.0 批量编辑*****************************
        #region 12 批量编辑 + ActionResult SaveBatchData()
        /// <summary>
        ///  批量编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveBatchData()
        {
            int folder_id = RequestHelper.GetIntByName("folder_id");//导航id
            string file_id = RequestHelper.GetStrByName("file_id"),//作品id
                folder_path = RequestHelper.GetStrByName("folder_path"),//导航path
                org_unit = RequestHelper.GetStrByName("org_unit"),//所属单位：代码
                unit_name = RequestHelper.GetStrByName("unit_name"),//所属单位：名称
                file_classify = RequestHelper.GetStrByName("file_classify");//适合分类
            if(string.IsNullOrEmpty(file_id))
                return operateContext.RedirectAjax(1, "待修改的作品id为空！", "", "");
            if (folder_id<=0)
                return operateContext.RedirectAjax(1, "导航目录id异常！", "", "");
            if(string.IsNullOrEmpty(file_classify))
                return operateContext.RedirectAjax(1, "适合分类为空！", "", "");
            //if (string.IsNullOrEmpty(org_unit))
            //    return operateContext.RedirectAjax(1, "所属单位为空！", "", "");
            try
            {
                string[] fileID = file_id.Split(',');
                //编辑导航目录
                foreach (string item in fileID)
                {
                    int tempID = Convert.ToInt32(item);
                    T_DocumentFolderRelation rel = operateContext.bllSession.T_DocumentFolderRelation.Select(s => s.file_id == tempID).FirstOrDefault();
                    if (rel != null)
                        operateContext.bllSession.T_DocumentFolderRelation.Modify(new T_DocumentFolderRelation { folder_id = folder_id, folder_path = folder_path }, s => s.fr_id == rel.fr_id, "folder_id", "folder_path");
                    else
                        operateContext.bllSession.T_DocumentFolderRelation.Add(new T_DocumentFolderRelation { file_id = tempID, create_id = operateContext.Usr.user_id, folder_id = folder_id, folder_path = folder_path });
                }
                //编辑其他
                operateContext.bllSession.T_DocumentInfo.SaveBatchFile(file_id, file_classify, org_unit, unit_name);
                return operateContext.RedirectAjax(0, "数据更新成功~", "", "");
            }
            catch(Exception ex)
            {
                return operateContext.RedirectAjax(1, ex.Message, "", "");
            }
        }
        #endregion
    }
}
